package l.l.test;

import java.util.Stack;

/**
 * Created by llw on 2017/9/7.
 */
public class AAA {

    public boolean isOk(int[] pushA,int[] popA){
        if(pushA.length == 0) return true;
        int j = 0;
        Stack<Integer> stack = new Stack<>();
        for(int i = 0 ; i < popA.length; ++i){
            if(stack.isEmpty() || stack.peek() != popA[i]){
                int flag=0;
                while(j < pushA.length){
                    if(pushA[j]==popA[i]) {
                        flag=1;
                        j=j+1;
                        break;
                    }
                    stack.push(pushA[j++]);
                }
                if(flag ==0)return false;
            }else{
                stack.pop();
            }
        }
        return true;
    }

    public static void main(String[] args) {
        int[] push = {1,2,3,4,5};
        int[] popa= {4,5,3,2,1};
        int [] popb = {4,3,5,1,2};
        boolean result = new AAA().isOk(push, popb);
        System.out.println(result);
    }
}
